<?php
/**
* Yt.class.php
*
* YouTube Client
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/
require_once("Zend/Loader.php");
class Yt 
{
        private static $yt = null;
        
        static function getclient()
        {
        
            if ( !isSet (Yt::$yt)  ) 
            {
                // Load the proxy adapter class in addition to the other required classes
                Zend_Loader::loadClass('Zend_Http_Client_Adapter_Proxy');
                $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
                $ytOptions = &PEAR::getStaticProperty('CONFIG_INI','YOUTUBE');
                $config = null;
                // Configure the proxy connection with your hostname and portnumber
                if ( isSet($global['proxy']) )
                { 
                    $config = array(
                        'adapter'    => 'Zend_Http_Client_Adapter_Proxy',
                        'proxy_host' => isSet($global['proxy']) ? $global['proxy'] : null
                    );
                }

                Zend_Loader::loadClass('Zend_Gdata_HttpClient');
                $httpProxyClient = new Zend_Gdata_HttpClient(null,$config);


                Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
                $httpClient =  Zend_Gdata_ClientLogin::getHttpClient(
                              $username = $ytOptions['username'],
                              $password = $ytOptions['password'],
                              $service = 'youtube',
                              $client = $httpProxyClient);


                $developerKey = $ytOptions['key'];

                Zend_Loader::loadClass('Zend_Gdata_YouTube');

                Yt::$yt = new Zend_Gdata_YouTube($httpClient, null, null, $developerKey);

            }
            return Yt::$yt;

        }

        static function unSetClient()
        {
            Yt::$yt = null;
        }
}
?>
